using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VSYSPRDEF
    {
        public DataRow Convert2SYSPRDEF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySYSPRDEF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SYPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["SYPPROG"] = " ".PadRight(7 ); 
         dwReturn["SYPANW"] = " ".PadRight(30 ); 
         dwReturn["SYPBEZ"] = " ".PadRight(30 ); 
         dwReturn["SYPSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["SYPMODTYP"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZGL1"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZGL2"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZGL3"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZGL4"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZGL5"] = " ".PadRight(1 ); 
         dwReturn["SYPPFTAST"] = " ".PadRight(6 ); 
         dwReturn["SYPANWKRZ"] = " ".PadRight(4 ); 
         dwReturn["SYPFCALLG"] = " ".PadRight(2 ); 
         dwReturn["SYPFCNUM"] = " ".PadRight(2 ); 
         dwReturn["SYPBACKOUT"] = " ".PadRight(1 ); 
         dwReturn["SYPUPRO"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZZW1"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZZW2"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZZW3"] = " ".PadRight(1 ); 
         dwReturn["SYPVKZZW4"] = " ".PadRight(1 ); 
         dwReturn["SYPUSERPRG"] = " ".PadRight(1 ); 
         dwReturn["SYPREITER"] = " ".PadRight(1 ); 
         dwReturn["SYPBUTTON"] = " ".PadRight(1 ); 
         dwReturn["SYPTABLE"] = " ".PadRight(8 ); 
         dwReturn["SYPTIME"] = " ".PadRight(2 ); 
         dwReturn["SYPICON"] = " ".PadRight(2 ); 
         dwReturn["SYPFILLER"] = " ".PadRight(13 ); 
         dwReturn["SYPAEND"] = " ".PadRight(0 ); 
         dwReturn["SYPAENB"] = " ".PadRight(8 ); 
         dwReturn["SYPNEUD"] = " ".PadRight(0 ); 
         dwReturn["SYPNEUB"] = " ".PadRight(8 ); 
         dwReturn["SYPAENZL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapSYSPRDEF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveSYSPRDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QuerySYSPRDEF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSYSPRDEF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertSYSPRDEF(dwLocal, ITXDBVERSION);
            }
            UpdateSYSPRDEF(dwLocal);
        }
        public void InsertSYSPRDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO SYSPRDEF(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QuerySYSPRDEF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SYSPRDEF WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM SYSPRDEF  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "SYSPRDEF";
            Return = Result;
            return Return;
        }
        public void DeleteSYSPRDEF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM SYSPRDEF   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateSYSPRDEF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE SYSPRDEF SET "
                    +"SYPMANDANT= :SYPMANDANT,"
                    +"SYPPROG= :SYPPROG,"
                    +"SYPANW= :SYPANW,"
                    +"SYPBEZ= :SYPBEZ,"
                    +"SYPSTAKZ= :SYPSTAKZ,"
                    +"SYPMODTYP= :SYPMODTYP,"
                    +"SYPVKZGL1= :SYPVKZGL1,"
                    +"SYPVKZGL2= :SYPVKZGL2,"
                    +"SYPVKZGL3= :SYPVKZGL3,"
                    +"SYPVKZGL4= :SYPVKZGL4,"
                    +"SYPVKZGL5= :SYPVKZGL5,"
                    +"SYPPFTAST= :SYPPFTAST,"
                    +"SYPANWKRZ= :SYPANWKRZ,"
                    +"SYPFCALLG= :SYPFCALLG,"
                    +"SYPFCNUM= :SYPFCNUM,"
                    +"SYPBACKOUT= :SYPBACKOUT,"
                    +"SYPUPRO= :SYPUPRO,"
                    +"SYPVKZZW1= :SYPVKZZW1,"
                    +"SYPVKZZW2= :SYPVKZZW2,"
                    +"SYPVKZZW3= :SYPVKZZW3,"
                    +"SYPVKZZW4= :SYPVKZZW4,"
                    +"SYPUSERPRG= :SYPUSERPRG,"
                    +"SYPREITER= :SYPREITER,"
                    +"SYPBUTTON= :SYPBUTTON,"
                    +"SYPTABLE= :SYPTABLE,"
                    +"SYPTIME= :SYPTIME,"
                    +"SYPICON= :SYPICON,"
                    +"SYPFILLER= :SYPFILLER,"
                    +"SYPAEND= :SYPAEND,"
                    +"SYPAENB= :SYPAENB,"
                    +"SYPNEUD= :SYPNEUD,"
                    +"SYPNEUB= :SYPNEUB,"
                    +"SYPAENZL= :SYPAENZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SYPMANDANT", OracleType.NVarChar).Value = dwData["SYPMANDANT"].ToString(); 
          or1.Parameters.Add("SYPPROG", OracleType.NVarChar).Value = dwData["SYPPROG"].ToString(); 
          or1.Parameters.Add("SYPANW", OracleType.NVarChar).Value = dwData["SYPANW"].ToString(); 
          or1.Parameters.Add("SYPBEZ", OracleType.NVarChar).Value = dwData["SYPBEZ"].ToString(); 
          or1.Parameters.Add("SYPSTAKZ", OracleType.NVarChar).Value = dwData["SYPSTAKZ"].ToString(); 
          or1.Parameters.Add("SYPMODTYP", OracleType.NVarChar).Value = dwData["SYPMODTYP"].ToString(); 
          or1.Parameters.Add("SYPVKZGL1", OracleType.NVarChar).Value = dwData["SYPVKZGL1"].ToString(); 
          or1.Parameters.Add("SYPVKZGL2", OracleType.NVarChar).Value = dwData["SYPVKZGL2"].ToString(); 
          or1.Parameters.Add("SYPVKZGL3", OracleType.NVarChar).Value = dwData["SYPVKZGL3"].ToString(); 
          or1.Parameters.Add("SYPVKZGL4", OracleType.NVarChar).Value = dwData["SYPVKZGL4"].ToString(); 
          or1.Parameters.Add("SYPVKZGL5", OracleType.NVarChar).Value = dwData["SYPVKZGL5"].ToString(); 
          or1.Parameters.Add("SYPPFTAST", OracleType.NVarChar).Value = dwData["SYPPFTAST"].ToString(); 
          or1.Parameters.Add("SYPANWKRZ", OracleType.NVarChar).Value = dwData["SYPANWKRZ"].ToString(); 
          or1.Parameters.Add("SYPFCALLG", OracleType.NVarChar).Value = dwData["SYPFCALLG"].ToString(); 
          or1.Parameters.Add("SYPFCNUM", OracleType.NVarChar).Value = dwData["SYPFCNUM"].ToString(); 
          or1.Parameters.Add("SYPBACKOUT", OracleType.NVarChar).Value = dwData["SYPBACKOUT"].ToString(); 
          or1.Parameters.Add("SYPUPRO", OracleType.NVarChar).Value = dwData["SYPUPRO"].ToString(); 
          or1.Parameters.Add("SYPVKZZW1", OracleType.NVarChar).Value = dwData["SYPVKZZW1"].ToString(); 
          or1.Parameters.Add("SYPVKZZW2", OracleType.NVarChar).Value = dwData["SYPVKZZW2"].ToString(); 
          or1.Parameters.Add("SYPVKZZW3", OracleType.NVarChar).Value = dwData["SYPVKZZW3"].ToString(); 
          or1.Parameters.Add("SYPVKZZW4", OracleType.NVarChar).Value = dwData["SYPVKZZW4"].ToString(); 
          or1.Parameters.Add("SYPUSERPRG", OracleType.NVarChar).Value = dwData["SYPUSERPRG"].ToString(); 
          or1.Parameters.Add("SYPREITER", OracleType.NVarChar).Value = dwData["SYPREITER"].ToString(); 
          or1.Parameters.Add("SYPBUTTON", OracleType.NVarChar).Value = dwData["SYPBUTTON"].ToString(); 
          or1.Parameters.Add("SYPTABLE", OracleType.NVarChar).Value = dwData["SYPTABLE"].ToString(); 
          or1.Parameters.Add("SYPTIME", OracleType.NVarChar).Value = dwData["SYPTIME"].ToString(); 
          or1.Parameters.Add("SYPICON", OracleType.NVarChar).Value = dwData["SYPICON"].ToString(); 
          or1.Parameters.Add("SYPFILLER", OracleType.NVarChar).Value = dwData["SYPFILLER"].ToString(); 
          or1.Parameters.Add("SYPAEND", OracleType.NVarChar).Value = dwData["SYPAEND"].ToString(); 
          or1.Parameters.Add("SYPAENB", OracleType.NVarChar).Value = dwData["SYPAENB"].ToString(); 
          or1.Parameters.Add("SYPNEUD", OracleType.NVarChar).Value = dwData["SYPNEUD"].ToString(); 
          or1.Parameters.Add("SYPNEUB", OracleType.NVarChar).Value = dwData["SYPNEUB"].ToString(); 
          or1.Parameters.Add("SYPAENZL", OracleType.NVarChar).Value = dwData["SYPAENZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
